<template>
  <ContentWrap>
    <el-descriptions :column="2" border label-width="160">
      <el-descriptions-item label="付款编号">
        {{ detailData.payCode }}
      </el-descriptions-item>
      <el-descriptions-item label="申请人">
        {{ detailData.userName }}
      </el-descriptions-item>
      <el-descriptions-item label="申请部门名称">
        {{ detailData.deptName }}
      </el-descriptions-item>
      <el-descriptions-item label="费用名称">
         <dict-tag :type="detailData.expenseType ?? ''" :value="detailData.expenseName ?? ''" />
      </el-descriptions-item>
      <el-descriptions-item label="费用类型">
        <dict-tag :type="DICT_TYPE.OA_EXPENSE_TYPE" :value="detailData.expenseType ?? ''" />
      </el-descriptions-item>
      <el-descriptions-item label="付款公司">
        {{ detailData.payCompany }}
      </el-descriptions-item>
      <el-descriptions-item label="付款人">
        {{ detailData.payerName }}
      </el-descriptions-item>
      <el-descriptions-item label="付款方式">
        <dict-tag :type="DICT_TYPE.OA_PAY_METHOD" :value="detailData.payMethod ?? ''" />
      </el-descriptions-item>
      <el-descriptions-item label="付款日期" prop="payDate">
        {{ formatDate(detailData.payDate, 'YYYY-MM-DD') }}
      </el-descriptions-item>
      <el-descriptions-item label="付款金额">
        {{ detailData.payAmount }} 元
      </el-descriptions-item>
      <el-descriptions-item label="收款人全称">
        {{ detailData.receiverName }}
      </el-descriptions-item>
      <el-descriptions-item label="收款人账号">
        {{ detailData.receiverAccount }}
      </el-descriptions-item>
      <el-descriptions-item label="收款人开户行">
        {{ detailData.receiverBank }}
      </el-descriptions-item>
      <el-descriptions-item label="有无发票" prop="hasInvoice">
          <el-tag>{{detailData.hasInvoice===1?'有':'无'}}</el-tag>
      </el-descriptions-item>
      <!-- <el-descriptions-item label="发票金额">
        {{ detailData.invoiceAmount }}
      </el-descriptions-item> -->

      <el-descriptions-item label="支付状态">
        <span v-if="detailData.payStatus === 1">已支付</span>
        <span v-else-if="detailData.payStatus === 2">已取消</span>
        <span v-else>未支付</span>
      </el-descriptions-item>
      <el-descriptions-item label="审批结果">
        <dict-tag :type="DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS" :value="detailData.status ?? '' " />
      </el-descriptions-item>

      <el-descriptions-item label="创建者">
        {{ detailData.creatorName }}
      </el-descriptions-item>
      <el-descriptions-item label=""/>
      <el-descriptions-item label="备注" :span="2">
        {{ detailData.remark }}
      </el-descriptions-item>
      <el-descriptions-item label="附件" :span="2">
        <OaFileManager :header="false"  :initial-file-ids="detailData.files" />
      </el-descriptions-item>
      
    </el-descriptions>
  </ContentWrap>
</template>
<script lang="ts" setup>
import { DICT_TYPE } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import { propTypes } from '@/utils/propTypes'
import { PaymentApi, PaymentVO } from '@/api/oa/payment'

defineOptions({ name: 'oaPaymentDetail' })

const { query } = useRoute() // 查询参数

const props = defineProps({
  id: propTypes.number.def(undefined)
})
const detailLoading = ref(false) // 表单的加载中
const detailData = ref<any>({}) // 详情数据
const queryId = query.id as unknown as number // 从 URL 传递过来的 id 编号

/** 获得数据 */
const getInfo = async () => {
  detailLoading.value = true
  try {
    detailData.value = await PaymentApi.getPayment(props.id || queryId)
  } finally {
    detailLoading.value = false
  }
}
defineExpose({ open: getInfo }) // 提供 open 方法，用于打开弹窗

// 监听id变化，重新获取数据
watch(() => props.id, (newId) => {
  if (newId) {
    getInfo()
  }
}, { immediate: false })

/** 初始化 **/
onMounted(() => {
  getInfo()
})
</script>
